package com.xydtech.ecard.config.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.ecard.config.domain.EcardNewsChannelList;
import com.xydtech.ecard.config.service.IEcardNewsChannelListService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电子名片新闻频道Controller
 *
 * @author JHON
 * @date 2022-04-08
 */
@Controller
@RequestMapping("/config/channelList")
public class EcardNewsChannelListController extends BaseController {
    private String prefix = "config/channelList";

    @Autowired
    private IEcardNewsChannelListService ecardNewsChannelListService;

    @RequiresPermissions("config:channelList:view")
    @GetMapping()
    public String channelList() {
        return prefix + "/channelList";
    }

    /**
     * 查询电子名片新闻频道列表
     */
    @RequiresPermissions("config:channelList:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardNewsChannelList ecardNewsChannelList) {
        startPage();
        List<EcardNewsChannelList> list = ecardNewsChannelListService.selectEcardNewsChannelListList(ecardNewsChannelList);
        return getDataTable(list);
    }

    /**
     * 通过接口下载电子名片新闻频道列表
     */
    @RequiresPermissions("config:channelList:downLoad")
    @Log(title = "通过接口下载电子名片新闻频道列表", businessType = BusinessType.IMPORT)
    @PostMapping("/downLoad")
    @ResponseBody
    public AjaxResult downLoad(Long deptId) {

        return ecardNewsChannelListService.downLoadNewsChannelList(deptId);
    }

    /**
     * 新增电子名片新闻频道
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存电子名片新闻频道
     */
    @RequiresPermissions("config:channelList:add")
    @Log(title = "电子名片新闻频道", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardNewsChannelList ecardNewsChannelList) {
        return toAjax(ecardNewsChannelListService.insertEcardNewsChannelList(ecardNewsChannelList));
    }

    /**
     * 修改电子名片新闻频道
     */
    @GetMapping("/edit/{channelId}")
    public String edit(@PathVariable("channelId") String channelId, ModelMap mmap) {
        EcardNewsChannelList ecardNewsChannelList = ecardNewsChannelListService.selectEcardNewsChannelListById(channelId);
        mmap.put("ecardNewsChannelList", ecardNewsChannelList);
        return prefix + "/edit";
    }

    /**
     * 修改保存电子名片新闻频道
     */
    @RequiresPermissions("config:channelList:edit")
    @Log(title = "电子名片新闻频道", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardNewsChannelList ecardNewsChannelList) {
        return toAjax(ecardNewsChannelListService.updateEcardNewsChannelList(ecardNewsChannelList));
    }

    /**
     * 删除电子名片新闻频道
     */
    @RequiresPermissions("config:channelList:remove")
    @Log(title = "电子名片新闻频道", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ecardNewsChannelListService.deleteEcardNewsChannelListByIds(ids));
    }

    /**
     * 查询新闻频道下拉列表
     */
    @PostMapping("/channelList")
    @ResponseBody
    public AjaxResult channelList(Long deptId) {
        EcardNewsChannelList ecardNewsChannelList = new EcardNewsChannelList();
//        ecardNewsChannelList.setDeptId(deptId);
        ecardNewsChannelList.setSts("1");
        List<EcardNewsChannelList> list = ecardNewsChannelListService.selectEcardNewsChannelListList(ecardNewsChannelList);
        return AjaxResult.success(list);
    }
}
